home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14511 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: nwlink.com!usenet
  2. From: Teresa Reiko <tjr19@mail.nwlink.com>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Obtaining file lists in C?
  5. Date: 15 Apr 1996 14:14:57 GMT
  6. Organization: Northwest Link
  7. Message-ID: <4ktll1$bk5@texas.nwlink.com>
  8. References: <gcraig.1.001653A2@interaccess.com>
  9. NNTP-Posting-Host: port55.annex2.nwlink.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.2 (Windows; U; 16bit)
  14.  
  15. gcraig@interaccess.com (George Craig) wrote:
  16. >Could someone please tell me just one of the many ways I could implement an 
  17. >efficient file listing technique in standard ANSI or k&R c?
  18. >
  19. >I.e, I want to obtain a listing of the files in the current directory - could 
  20. >I use a pointer to an array of strings? Whereas the strings are actually the 
  21. >names of the files in the current directory.
  22. >
  23. >If I could do that... (which I am almost positive I can) how would I obtain 
  24. >the file listing into the variables. I want to avoid using system() and I 
  25. >surely don't want to go low-level and read the file system's table(s) - any 
  26. >and all help will surely be appreciated -- Thank you
  27.  
  28. This is impossible in standard C.  There is no standard C function to
  29. read the directories.  Most C implementations include one, however, so
  30. for instance in Borland C you can use findfirst and findnext, or you
  31. can use opendir, readdir, etc.
  32.  
  33. system() is a standard C function, but its use for this would not be
  34. portable either because: on Unix the directory list command is 'ls',
  35. but on DOS it is 'dir', so you can't count on that.
  36.  
  37. Unfortunately, this sort of program is just not portable!
  38.  
  39. ----- for every vision there is an equal and opposite revision ... -----
  40. ------------------------------------------------------------------------
  41.  Teresa Reiko    Chief Programmer, Tenbyte Software    tjr19@nwlink.com
  42. ------------------------------------------------------------------------
  43.  
  44.